package com.wanmait.wanmarecruit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wanmait.wanmarecruit.service.EducationExperienceService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanmait.wanmarecruit.mapper.EducationalExperienceMapper;
import com.wanmait.wanmarecruit.entity.EducationalExperience;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class EducationalExperienceServiceImpl extends ServiceImpl<EducationalExperienceMapper, EducationalExperience> implements EducationExperienceService {

    @Override
    public List<EducationalExperience> getEducationByUser(Integer userId) {
        LambdaQueryWrapper<EducationalExperience> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EducationalExperience::getUserId,userId);
        return this.list(queryWrapper);
    }

    @Override
    public void saveSomeEducation(Integer userId, List<EducationalExperience> educationalExperienceList) {
        educationalExperienceList.forEach(educationalExperience -> educationalExperience.setUserId(userId));
        LambdaQueryWrapper<EducationalExperience> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EducationalExperience::getUserId,userId);
        this.remove(queryWrapper);
        this.saveBatch(educationalExperienceList);
    }
}
